#!/usr/bin/env python

# -*- coding: utf-8 -*-

"""

__title__ = ''

__author__ = 'hu'

__mtime__ = '2018/3/21'

"""

from django.views.generic.base import View
from apps.goods.models import Goods


class GoodsListView(View):
    def get(self, request):
        """
        通过view实现商品列表页
        :param request:
        :return:
        """
        jsonlist = []
        goods = Goods.objects.all()[:10]
        for good in goods:
            json_dict = {}
            json_dict["name"] = good.name
            json_dict["category"] = good.category.name
            json_dict["market_price"] = good.market_price
            json_dict["add_time"] = good.add_time
            jsonlist.append(json_dict)

        from django.http import HttpResponse
        import json
        from utils.serialized import DateEncoder
        return HttpResponse(json.dumps(jsonlist, cls=DateEncoder), content_type="application/json")
